package com.cadre.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cadre.entity.Letter;
import com.cadre.entity.User;
import com.cadre.service.LetterServiceImpl;
import com.cadre.service.UserServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
public class LetterController {
	@Autowired
    private LetterServiceImpl letterService;
	
	@RequestMapping("/UseraddLetter")
	public String  UaddLetter(Letter letter,Model model,HttpServletRequest requset){
			boolean resultletter = this.letterService.addLetter(letter);
			if(resultletter){
			model.addAttribute("letter",resultletter);
			return "email.jsp";
			}else{
			return "/test.jsp";
			}
	}
	
	
	@RequestMapping("/CadreaddLetter")
	public String  CaddLetter(Letter letter,Model model,HttpServletRequest requset){
			boolean resultletter = this.letterService.addLetter(letter);
			
			if(resultletter){
			model.addAttribute("letter",resultletter);
			return "cadreemail.jsp";
			}else{
			return "/test.jsp";
			}
	}
		/*
		 * 以下是admin操作
		 */
		
	//搜索所有信件
	@RequestMapping("/selectAllLetter")
	public String selectLetter(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")
	int pageSize,Model model,HttpServletRequest request){
		PageHelper.startPage(pageNum, pageSize);
		List<Letter> list = this.letterService.selectAllLetter();
		PageInfo<Letter> page=new PageInfo<Letter>(list);
		System.out.println("Controller层");
		model.addAttribute("letter", list);
		model.addAttribute("page", page);
		
		
		return "/showLetter.jsp";
}
	
	
	
	
	
	
	
	
	
		
		
}
